package com.example.intermediateactivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.intermediateactivity.adapters.CustomButtonBaseAdapter;
import com.example.intermediateactivity.beans.Dog;
import com.example.intermediateactivity.utils.ToastHelper;

import java.util.List;

public class ListViewClickEvent extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view_click_event);

        ListView listView = findViewById(R.id.lv_list);
        List<Dog> dataList = Dog.getDefaultList();
        CustomButtonBaseAdapter adapter = new CustomButtonBaseAdapter(this, dataList);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener((adapterView, view, i, l) -> {
            ToastHelper.show(ListViewClickEvent.this, "点击了" + dataList.get(i).name);
        });
    }
}